//
//  LGNetWorkingManager+Extensition.m
//  微博oc版
//
//  Created by Apple_Lzzy27 on 16/10/13.
//  Copyright © 2016年 Apple_Lzzy27. All rights reserved.
//

#import "LGNetWorkingManager+Extensition.h"

@implementation LGNetWorkingManager (Extensition)


//获取某个的各种消息未读数

- (void)unreadCount:(void(^)(int count))copletion{
    
   NSString *url = @"https://rm.api.weibo.com/2/remind/unread_count.json";
    NSMutableDictionary  *parameters = [NSMutableDictionary dictionary];
    
    [parameters setObject:@"1945146207" forKey:@"uid"];
    
    
    //发送请求
    [self tokenReques:GET urlString:url parameters:parameters completion:^(BOOL isSuccess, NSDictionary  *responseObject) {
        int count = (int)[responseObject[@"status"] integerValue];
        copletion(count);
        
    }];
    
    
    
}




/**
 *  获取用户好友微博消息列表
 *
 *  @param completion 完成回调
 */
- (void)statusList:(NSUInteger)max_id since_id:(NSUInteger)since_id completion:(void(^)(BOOL isSuccess,NSArray* json))completion{
       //url
    //创建一个单列//    completion:(void (^)(BOOL isSuccess,id responseObject))completion
    NSString *url = @"https://api.weibo.com/2/statuses/friends_timeline.json";
    NSUInteger maxid = max_id <= 0 ? 0 : max_id -1;
    
        NSString *max = [NSString stringWithFormat:@"%zd",maxid];
     NSString *sin = [NSString stringWithFormat:@"%zd",since_id];
    
    NSMutableDictionary *parameters =[NSMutableDictionary dictionary];
    [parameters setObject:sin forKey:@"since_id"];
     [parameters setObject:max forKey:@"max_id"];
  
    [self tokenReques:GET urlString:url parameters:parameters completion:^(BOOL isSuccess, id responseObject) {
        
        NSArray *array = responseObject[@"statuses"];
        
        completion(isSuccess,array);

    }];
    
    
}





//发送请求获取token

-(void)loadTokenRequest:(NSString *)code completion:(void(^)(bool isSuccess))completion{
    //参数
  
   
    NSString *url = @"https://api.weibo.com/oauth2/access_token";
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    params[@"client_id"]=@"800817303";
    params[@"client_secret"]=@"37af1178bb1f21ae62d7a566f685a6fb";
    params[@"grant_type"]=@"authorization_code";
    params[@"redirect_uri"]=@"http://52it.me";
    params[@"code"]=code;


    [self request:POST urlString:url parameters:params completion:^(BOOL isSuccess, id  _Nullable responseObject) {
        NSLog(@"%@",responseObject);
        completion(isSuccess);
        
    }];
}



@end
